home *** CD-ROM | disk | FTP | other *** search
- Path: ns1.win.net!dorsea!nehager
- Newsgroups: comp.lang.c++
- Message-ID: <1476@dorsea.win.net>
- Reply-To: nehager@dorsea.win.net (Nat Hager III)
- From: nehager@dorsea.win.net (Nat Hager III)
- Date: Thu, 01 Feb 1996 22:23:00 GMT
- Subject: disk I/O - large binary array problem
-
- Hi folks,
-
- I'm having a problem writing large arrays to disk using the
- ofstream and ifstream write and read functions. Things work
- properly for the first 100 or so elements, but then the rogue
- value appears (like 3.9E-320), and the whole thing bombs out, with
- the remaining elements written as zero. An ideas? Could it be a
- stream flushing problem, a buffer problem, a stack problem, crossing
- a segment boundary? Sorry if these are dumb suggestions, but I'm a
- relative newbie.
-
- I've tried writing the data both as a struct and on an
- element-by-element basis as an array, so I don't think it has to
- do with my struct usage. Here's a sample program:
-
- Thank you,
- Nat Hager
-
- ---------snip--------snip--------snip---------
-
-
- struct datafile
- {
- double test_array1[400];
- };
-
- datafile tdr;
-
- void file_write()
- {
- for (int i=0;i<400;i++)
- {
- tdr.test_array1[i] = i/1e9; // initialize it to something
- }
- ofstream tfile("crap.dat"); // binary write to file
- tfile.write( (char*) &tdr, sizeof tdr );
- tfile.close;
- }
-
- void file_read()
- {
- ifstream tfile("crap.dat");
- tfile.read((char*) &tdr, sizeof tdr ); // binary read from file
- for ( int i=0; i<400;i++)
- {
- cout << i << '\t' << tdr.test_array1 [i] << '\n'; //print
- }
- tfile.close;
- }
-
-
- Nat Hager III nehager@dorsea.win.net
- 772 Dorsea Rd. 71552.513@compuserve.com
- Lancaster, PA 17601 hagerne@vax.etown.edu
- (717) 898-3053 (717) 361-1377
-
-